function func() {
    function getNumberOfElemtns() {
        var number = document.getElementById("numberOfElements").value;
        return number;
    }

    function createOption(val, name) {
        var option = document.createElement("option");
        option.value = val;
        var optionText = document.createTextNode(name);
        option.appendChild(optionText);
        return option;
    }

    function createSelectBox() {
        var selectBox = document.createElement("select");
        selectBox.name = "fieldType";
        selectBox.form = "eventForm";
        var option = createOption("text", "Text Field");
        selectBox.appendChild(option);
        option = createOption("color", "Color Field");
        selectBox.appendChild(option);
        return selectBox;
    }

    function createNodes(form,id,name,sel) {
        var label = document.createElement("label");
        var labelText = document.createTextNode("Element Name:");
        label.appendChild(labelText);
        form.appendChild(label);
        var input = document.createElement("input");
        input.type = "text";
        input.name = name;
        input.id = id;
        form.appendChild(input);
        var label_1 = document.createElement("label");
        var label_1Text = document.createTextNode("Element Type:");
        label_1.appendChild(label_1Text);
        form.appendChild(label_1);
        var selectBox = createSelectBox();
        selectBox.name = "0"+sel;
        form.appendChild(selectBox);
    }


    document.getElementById("btn").addEventListener('click', function() {
        //window.location.href = "elements.html";
        var n = getNumberOfElemtns();
        var eventForm = document.getElementById("eventForm");
        console.log(eventForm);
        for (var i = 0; i < n; i++) {
            createNodes(eventForm,i,i,i);
        }
        var preview = document.getElementById("previewForm");
        document.getElementById("gen").addEventListener('click', function() {
            preview.innerHTML = "<label>" + document.getElementById("0").value + "</label>" + 
            "<input type='"+eventForm["00"].value+"'></input>";
            console.log(eventForm["0"].value);
        }, false);
    }, false);

}

window.addEventListener('load', func, false);
